package part1.language_basis.day05.day05test;

import java.util.Arrays;
import java.util.Scanner;

public class Addition2 {
    public static void main(String[] args) {

        /** Addition随机加法运算器
         要求：由系统随机出10道加法题，而后由用户来答题，
         答题后输出"答对了"或"答错了"，答对1题得10分，答
         错1题不扣分，最后输出总分数 */
        Scanner scanner = new Scanner(System.in);
        int score = 0;
        for (int i = 1; i <= 10; i++) {
            int a = (int) (Math.random()*100);
            int b = (int) (Math.random()*100);
            int result = a+b;
            System.out.println("("+i+")"+a+"+"+b+"=?");
            System.out.println("算吧");
            int answer = scanner.nextInt();
            if (answer==-1){
                break;
            }
            if (answer==result){
                System.out.println("答对了");
                score += 10;
            }else{
                System.out.println("答错了");
            }
        }
        System.out.println("总分为："+score);


        /** 2. MultiTable九九乘法表
         要求：输出九九乘法表 */
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j+"*"+i+"="+j*i+"\t");
            }
            System.out.println();
        }



        /** 3. 数组小代码练习：声明、初始化、访问、遍历 */
        int[] arr1 = new int[10];
        int[] arr2 = new int[]{12,4,56,7,65};
        int[] arr3 = {134,54,6,43,5};
        int[] arr4;
        //arr4 = {132,56,45}; //编译错误 此方式只能声明的同时赋值
        arr4 = new int[]{13,34,45,4};
        System.out.println(arr2[3]);
        //System.out.println(arr2[7]); //运行时为报数组下标越界异常
        System.out.println(arr3.length);
        for (int i = 0; i < arr1.length; i++) {
            arr1[i] = (int) (Math.random()*100);
            System.out.println(arr1[i]);
        }


        /** 4. MaxOfArray求数组元素最大值 */
        int[] arr5 = new int[10];
        for (int i = 0; i < arr5.length; i++) {
            arr5[i] = (int) (Math.random()*100);
            System.out.println(arr5[i]);
        }
        int max = arr5[0];
        for (int i = 0; i < arr5.length; i++) {
            if (arr5[i]>max){
                max = arr5[i];
            }
        }
        System.out.println("最大值为："+max);


        /** 5. 对数组进行升序排列，并输出排序后的结果 */
        int[] arr6 = new int[10];
        for (int i = 0; i < arr6.length; i++) {
            arr6[i] = (int) (Math.random()*100);
            System.out.println(arr6[i]);
        }
        Arrays.sort(arr6);
        System.out.println("排序后");
        for (int i = 0; i < arr6.length; i++) {
            System.out.println(arr6[i]);
        }
    }
}
